package xycdao

import (
	"Cgo/front/models"
	"Cgo/global"
)

type xycUserDao struct{}

var XycUserDao = xycUserDao{}

func (xyc xycUserDao) UserLoginDao(user models.XycUser) (models.XycUser, error) {
	if r := global.DB.Where("account = ? AND password = ?", user.Account, user.Password).First(&user); r.Error != nil {
		return user, r.Error
	} else {
		return user, nil
	}
}

func (xyc xycUserDao) UserRegisterDao(user models.XycUser) error {
	if r := global.DB.Create(&user); r.Error != nil {
		return r.Error
	} else {
		return nil
	}
}

func (xyc xycUserDao) UserUpdateDao(user models.XycUser) error {
	if r := global.DB.Save(&user); r.Error != nil {
		return r.Error
	} else {
		return nil
	}
}

func (xyc xycUserDao) UserDeleteDao(user models.XycUser) error {
	if r := global.DB.Delete(&user); r.Error != nil {
		return r.Error
	} else {
		return nil
	}
}

func (xyc xycUserDao) UserFindDao(user models.XycUser) ([]models.XycUser, error) {
	var users []models.XycUser
	if r := global.DB.Where(&user).Find(&users); r.Error != nil {
		return users, r.Error
	} else {
		return users, nil
	}
}
